﻿using System;
using System.Collections.Generic;
using System.Text;
using AirlineCommon;
using System.Data;
namespace AirlineSystemApp
{
    public class ScheduleFlightConcrete : ScheduleFlightBuilder
    {
        public ScheduleFlightConcrete()
        {
            ScheduleFlightProduct = new ScheduleFlightProduct();
        }
    
        public override void BuildScheduleList()
        {
            IAirlineServices ai = new AirlineServiceFacade.AirlineServices();
            List<ScheduledFlight> list = new List<ScheduledFlight>();
            DataSet ds = ai.GetScheduleFlightList();
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ScheduledFlight sc = new ScheduledFlight();
                    sc.FlightNo = dr["FlightNo"].ToString();
                    sc.FlightDate = DateTime.Parse(dr["FlightDate"].ToString());
                    sc.FirstClassSeatsAvailable = int.Parse(dr["FirstClassSeatsAvailable"].ToString());
                    sc.BusinessClassSeatsAvailable = int.Parse(dr["BusinessClassSeatsAvailable"].ToString());
                    sc.EconomyClassSeatsAvailable = int.Parse(dr["EconomyClassSeatsAvailable"].ToString());
                    list.Add(sc);
                }
            }
            ScheduleFlightProduct.ScheduledFlightList = list;
        }

        public override void BuildScheduleDetail()
        {
            ScheduleFlightProduct.ScheduledFlight = ScheduleFlightProduct.ScheduledFlightList[ScheduleFlightProduct.Index];
        }
    }
}
